package com.deng.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deng.api.entity.CloudDepartment;
import com.deng.api.mapper.CloudDepartmentMapper;
import com.deng.api.service.ICloudDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deng.api.vo.PageVO;
import com.deng.commons.common.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author deng
 * @since 2022-08-10
 */
@Service
public class CloudDepartmentServiceImpl extends ServiceImpl<CloudDepartmentMapper, CloudDepartment> implements ICloudDepartmentService {
    @Resource
    private CloudDepartmentMapper cloudDepartmentMapper;

    @Override
    public BaseResult<CloudDepartment> getDeptAll(Integer page, Integer size, String name) {
//        Page<CloudDepartment> p = new Page<>(page,size);
//        LambdaQueryWrapper<CloudDepartment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        if (!StrUtil.isEmptyIfStr(name)){
//            lambdaQueryWrapper.like(CloudDepartment::getDepartment,name);
//        }
//        Page<CloudDepartment> cloudDepartmentPage = cloudDepartmentMapper.selectPage(p, lambdaQueryWrapper);
//        return BaseResult.success(PageVO.toPageVO(cloudDepartmentPage));
        List<CloudDepartment> deptAll = cloudDepartmentMapper.getDeptAll(page, size, name);
        Long count = Long.valueOf(cloudDepartmentMapper.getCount());
        return BaseResult.success(new PageVO<List<CloudDepartment>>(deptAll,count));
    }
}
